{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from IPython.display import Image\n",
    "from numpy import pi\n",
    "from qutip import *\n",
    "import numpy as np\n",
    "from qutip.qip.circuit import *\n",
    "from qutip.qip.qubits import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "init = qubit_states(4,[0,0,1,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "Quantum object: dims = [[2, 2, 2, 2], [1, 1, 1, 1]], shape = (16, 1), type = ket\\begin{equation*}\\left(\\begin{array}{*{11}c}0.0\\\\0.0\\\\1.0\\\\0.0\\\\0.0\\\\\\vdots\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\\\end{array}\\right)\\end{equation*}"
      ],
      "text/plain": [
       "Quantum object: dims = [[2, 2, 2, 2], [1, 1, 1, 1]], shape = (16, 1), type = ket\n",
       "Qobj data =\n",
       "[[ 0.]\n",
       " [ 0.]\n",
       " [ 1.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]\n",
       " [ 0.]]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "init"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "qc1 = QubitCircuit(4)\n",
    "qc1.add_gate(\"SNOT\", 2)\n",
    "\n",
    "qc1.add_gate(\"SNOT\", 0)\n",
    "qc1.add_gate(\"SNOT\", 1)\n",
    "qc1.add_gate(\"F1\", 2, 0)\n",
    "qc1.add_gate(\"F2\", 2, 1)\n",
    "qc1.add_gate(\"SWAP\", [1,0])\n",
    "qc1.add_gate(\"SNOT\", 1)\n",
    "qc1.add_gate(\"SINV\", 0, 1)\n",
    "qc1.add_gate(\"SNOT\", 0)\n",
    "qc1.add_gate(\"RY4\", 3, 1)\n",
    "qc1.add_gate(\"RY8\", 3, 0)\n",
    "qc1.add_gate(\"SNOT\", 0)\n",
    "qc1.add_gate(\"S\", 0, 1)\n",
    "qc1.add_gate(\"SNOT\", 1)\n",
    "qc1.add_gate(\"SWAP\", [1,0])\n",
    "qc1.add_gate(\"F2INV\", 2, 1)\n",
    "qc1.add_gate(\"F1INV\", 2, 0)\n",
    "qc1.add_gate(\"SNOT\", 0)\n",
    "qc1.add_gate(\"SNOT\", 1)\n",
    "\n",
    "qc1.add_gate(\"SIGMAX\", 2)\n",
    "qc1.add_gate(\"RYT1\", 1, 2)\n",
    "qc1.add_gate(\"CNOT\", 2, 3)\n",
    "qc1.add_gate(\"RYT1d\", 1, 2)\n",
    "qc1.add_gate(\"CNOT\", 2, 3)\n",
    "qc1.add_gate(\"RYT1\", 1, 2)\n",
    "qc1.add_gate(\"SIGMAX\", 2)\n",
    "\n",
    "qc1.add_gate(\"RYT2\", 1, 2)\n",
    "qc1.add_gate(\"CNOT\", 2, 3)\n",
    "qc1.add_gate(\"RYT2d\", 1, 2)\n",
    "qc1.add_gate(\"CNOT\", 2, 3)\n",
    "qc1.add_gate(\"RYT2\", 1, 2)\n",
    "\n",
    "qc1.add_gate(\"RYT0\", 1, 3)\n",
    "qc1.add_gate(\"CH\", 2, 3)\n",
    "qc1.add_gate(\"SWAP\", [3,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "qc2 = QubitCircuit(4)\n",
    "qc1.add_gate(\"RYT0\", 1, 3)\n",
    "\n",
    "U_list2 = qc2.propagators()\n",
    "U2 = gate_sequence_product(U_list2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "U_list1 = qc1.propagators()\n",
    "U1 = gate_sequence_product(U_list1)\n",
    "phi=U1*init"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "Quantum object: dims = [[2, 2, 2, 2], [2, 2, 2, 2]], shape = (16, 16), type = oper, isherm = True\\begin{equation*}\\left(\\begin{array}{*{11}c}0.707 & 0.0 & 0.707 & 0.0 & 0.0 & \\cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \\cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.707 & 0.0 & -0.707 & 0.0 & 0.0 & \\cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \\cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.707 & \\cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\\\vdots & \\vdots & \\vdots & \\vdots & \\vdots & \\ddots & \\vdots & \\vdots & \\vdots & \\vdots & \\vdots\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \\cdots & -0.707 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \\cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \\cdots & 0.0 & 0.0 & 0.707 & 0.0 & 0.707\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \\cdots & 0.0 & 0.0 & 0.0 & 0.0 & 0.0\\\\0.0 & 0.0 & 0.0 & 0.0 & 0.0 & \\cdots & 0.0 & 0.0 & 0.707 & 0.0 & -0.707\\\\\\end{array}\\right)\\end{equation*}"
      ],
      "text/plain": [
       "Quantum object: dims = [[2, 2, 2, 2], [2, 2, 2, 2]], shape = (16, 16), type = oper, isherm = True\n",
       "Qobj data =\n",
       "[[ 0.70710678  0.          0.70710678  0.          0.          0.          0.\n",
       "   0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.        ]\n",
       " [ 0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.70710678  0.          0.70710678  0.          0.          0.\n",
       "   0.          0.        ]\n",
       " [ 0.70710678  0.         -0.70710678  0.          0.          0.          0.\n",
       "   0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.        ]\n",
       " [ 0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.70710678  0.         -0.70710678  0.          0.          0.\n",
       "   0.          0.        ]\n",
       " [ 0.          0.          0.          0.          0.70710678  0.\n",
       "   0.70710678  0.          0.          0.          0.          0.          0.\n",
       "   0.          0.          0.        ]\n",
       " [ 0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.          0.          0.          0.          0.70710678\n",
       "   0.          0.70710678  0.        ]\n",
       " [ 0.          0.          0.          0.          0.70710678  0.\n",
       "  -0.70710678  0.          0.          0.          0.          0.          0.\n",
       "   0.          0.          0.        ]\n",
       " [ 0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.          0.          0.          0.          0.70710678\n",
       "   0.         -0.70710678  0.        ]\n",
       " [ 0.          0.70710678  0.          0.70710678  0.          0.          0.\n",
       "   0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.        ]\n",
       " [ 0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.          0.70710678  0.          0.70710678  0.          0.\n",
       "   0.          0.        ]\n",
       " [ 0.          0.70710678  0.         -0.70710678  0.          0.          0.\n",
       "   0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.        ]\n",
       " [ 0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.          0.70710678  0.         -0.70710678  0.          0.\n",
       "   0.          0.        ]\n",
       " [ 0.          0.          0.          0.          0.          0.70710678\n",
       "   0.          0.70710678  0.          0.          0.          0.          0.\n",
       "   0.          0.          0.        ]\n",
       " [ 0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.          0.          0.          0.          0.\n",
       "   0.70710678  0.          0.70710678]\n",
       " [ 0.          0.          0.          0.          0.          0.70710678\n",
       "   0.         -0.70710678  0.          0.          0.          0.          0.\n",
       "   0.          0.          0.        ]\n",
       " [ 0.          0.          0.          0.          0.          0.          0.\n",
       "   0.          0.          0.          0.          0.          0.\n",
       "   0.70710678  0.         -0.70710678]]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "U1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "Quantum object: dims = [[2, 2, 2, 2], [1, 1, 1, 1]], shape = (16, 1), type = ket\\begin{equation*}\\left(\\begin{array}{*{11}c}0.707\\\\0.0\\\\-0.707\\\\0.0\\\\0.0\\\\\\vdots\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\0.0\\\\\\end{array}\\right)\\end{equation*}"
      ],
      "text/plain": [
       "Quantum object: dims = [[2, 2, 2, 2], [1, 1, 1, 1]], shape = (16, 1), type = ket\n",
       "Qobj data =\n",
       "[[ 0.70710678]\n",
       " [ 0.        ]\n",
       " [-0.70710678]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]\n",
       " [ 0.        ]]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "phi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.]] I think this number is 9.\n"
     ]
    }
   ],
   "source": [
    "if np.sign(phi[14].real)==1:\n",
    "    print(phi[14].real,'I think this number is 6.')\n",
    "else:\n",
    "    print(phi[14].real,'I think this number is 9.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    ""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    ""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3.0
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}